//
//  PayAnimationViewController.m
//  Arts1
//
//  Created by Mac Jc on 15/10/13.
//  Copyright © 2015年 Arts1. All rights reserved.
//

#import "PayAnimationViewController.h"
#import "AllHeader.h"
#import "PayVC.h"

// 生成渐变开始颜色
#define kGradientStart [UIColor colorWithRed:230 % 256 / 255.0 green:0 % 256 / 255.0 blue:155 % 256 / 255.0 alpha:1]

// 生成渐变结束颜色
#define kGradientEnd [UIColor colorWithRed:150 % 256 / 255.0 green:10 % 256 / 255.0 blue:155 % 256 / 255.0 alpha:1]




@interface PayAnimationViewController ()
//  生成渐变层
@property (strong, nonatomic) CAGradientLayer *gradientLayer;



//  生成渐变层
@property (nonatomic, strong) UIView *gradientView;

//  会员条款
@property (nonatomic, strong) UILabel *arts1Label;
@property (nonatomic, strong) UILabel *cardName;
@property (nonatomic, strong) UILabel *priceLabel;
@property (nonatomic, strong) UILabel *dearCustomor;
@property (nonatomic, strong) UILabel *list1;
@property (nonatomic, strong) UILabel *list2;
@property (nonatomic, strong) UILabel *list3;
@property (nonatomic, strong) UIImageView *iamgeVIew;



@end



@implementation PayAnimationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor clearColor];
    
    [UIView viewOfBlurEffect:self.view withAlpha:1.0];
    
    [self payView];
    
    [UIView animateWithDuration:0.4 delay:0 options:(UIViewAnimationOptionCurveEaseInOut) animations:^{
        _backgroundView.frame = CGRectMake(25, SCREEN_HEIGHT / 2 - 210 / 2 - 50, SCREEN_WIDTH - 50, 210);
        
    } completion:^(BOOL finished) {
        [self changeContent];
    }];
}

- (void)changeContent{
    [UIView animateWithDuration:0.8 delay:1.2 options:(UIViewAnimationOptionCurveEaseInOut) animations:^{
        
        _arts1Label.alpha = 0;
        _gradientView.frame = CGRectMake(0, 0, _gradientView.size.width, _gradientView.size.height - 70);
        
        _cardName.frame = CGRectMake(15, _backgroundView.size.height - 55, 150, 20);
        _cardName.alpha = 1;
        
        _priceLabel.frame = CGRectMake(14,_cardName.bottom + 0, 150, 20);
        _priceLabel.alpha = 1;
        
        _dearCustomor.frame = CGRectMake(15,15, _backgroundView.size.width - 30, 20);
        _dearCustomor.alpha = 1;
        
        _list1.frame = CGRectMake(15, 70, _backgroundView.size.width - 30, 20);
        _list1.alpha = 1;
        
        _list2.frame = CGRectMake(15, _list1.bottom + 0, _backgroundView.size.width - 30, 20);
        _list2.alpha = 1;
        
        _list3.frame = CGRectMake(15, _list2.bottom + 0, _backgroundView.size.width - 30, 20);
        _list3.alpha = 1;
        
        _payButten.frame = CGRectMake(_backgroundView.size.width - 15 - 65, _backgroundView.size.height - 17 - 37, 65, 37);
        _payButten.alpha = 1;
        
    } completion:^(BOOL finished) {
        nil;
    }];
}


- (void)payView{
    
    _backgroundView = [[UIView alloc] initWithFrame:CGRectMake(25, SCREEN_HEIGHT, SCREEN_WIDTH - 50, 210)];
    _backgroundView.layer.cornerRadius = 15;
    _backgroundView.backgroundColor = [UIColor whiteColor];
    
    [UIView viewWideForShadowColor:_backgroundView];
    [self.view addSubview:_backgroundView];
    
    _gradientView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, _backgroundView.size.width, _backgroundView.size.height - 0)];
    
    UIBezierPath *maskPath=  [UIBezierPath bezierPathWithRoundedRect:_gradientView.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight | UIRectCornerBottomLeft |UIRectCornerBottomRight cornerRadii:CGSizeMake(15, 15)];
    CAShapeLayer *maskLayer=[[CAShapeLayer alloc] init];
    maskLayer.frame = _gradientView.bounds;
    maskLayer.path=maskPath.CGPath;
    _gradientView.layer.mask=maskLayer;
    _gradientView.layer.masksToBounds=YES;
    
    
    [_backgroundView addSubview:_gradientView];
    
    //初始化渐变层
    self.gradientLayer = [CAGradientLayer layer];
    self.gradientLayer.frame = _gradientView.bounds;
    [_gradientView.layer addSublayer:self.gradientLayer];
    
    //设置渐变颜色方向
    self.gradientLayer.startPoint = CGPointMake(0, 0);
    self.gradientLayer.endPoint = CGPointMake(1, 1);
    
    //设定颜色组
    self.gradientLayer.colors = @[(__bridge id)kGradientStart.CGColor,
                                  (__bridge id)kGradientEnd.CGColor];
    
    //设定颜色分割点
    self.gradientLayer.locations = @[@(0.5f) ,@(1.0f)];
    
    _arts1Label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, _gradientView.size.width, _gradientView.size.height)];
    _arts1Label.text = @"Arts1 VIP";
    _arts1Label.font = [UIFont boldSystemFontOfSize:48];
    _arts1Label.textColor = [UIColor whiteColor];
    [_arts1Label setTextAlignment:(NSTextAlignmentCenter)];
    [_gradientView addSubview:_arts1Label];
    
    _cardName = [[UILabel alloc] initWithFrame:CGRectMake(230, _backgroundView.size.height - 55, 150, 20)];
    _cardName.text = @"会员卡";
    _cardName.font = [UIFont boldSystemFontOfSize:18];
    _cardName.alpha = 0;
    _cardName.textColor = kGradientStart;
    [_backgroundView addSubview:_cardName];
    
    _priceLabel = [[UILabel alloc] initWithFrame:CGRectMake(250,_cardName.bottom + 0, 150, 20)];
    _priceLabel.text = _price;
    _priceLabel.font = [UIFont boldSystemFontOfSize:16];
    _priceLabel.alpha = 0;
    _priceLabel.textColor = kCustomColor(150, 150, 150, 1);
    [_backgroundView addSubview:_priceLabel];
    
    _dearCustomor = [[UILabel alloc] initWithFrame:CGRectMake(65,15, _backgroundView.size.width - 30, 20)];
    _dearCustomor.text = @"您将得到我们以下真诚的服务：";
    _dearCustomor.alpha = 0;
    _dearCustomor.font = [UIFont boldSystemFontOfSize:15];
    //    _dearCustomor.textColor = kCustomColor(40, 40, 50, 1);
    _dearCustomor.textColor = [UIColor whiteColor];
    [_backgroundView addSubview:_dearCustomor];
    
    _list1 = [[UILabel alloc] initWithFrame:CGRectMake(95, 70, _backgroundView.size.width - 30, 15)];
    _list1.text = @"实时在线客服";
    _list1.alpha = 0;
    _list1.font = [UIFont italicSystemFontOfSize:13];
    //    _list1.textColor = kCustomColor(150, 150, 150, 1);
    _list1.textColor = [UIColor whiteColor];
    [_backgroundView addSubview:_list1];
    
    _list2 = [[UILabel alloc] initWithFrame:CGRectMake(125, _list1.bottom + 0, _backgroundView.size.width - 30, 15)];
    _list2.text = @"最新考试动态提醒";
    _list2.alpha = 0;
    _list2.font = [UIFont italicSystemFontOfSize:13];
    //    _list2.textColor = kCustomColor(150, 150, 150, 1);
    _list2.textColor = [UIColor whiteColor];
    [_backgroundView addSubview:_list2];
    
    _list3 = [[UILabel alloc] initWithFrame:CGRectMake(155, _list2.bottom + 0, _backgroundView.size.width - 30, 15)];
    _list3.text = @"上千部视频无限次学习";
    _list3.alpha = 0;
    _list3.font = [UIFont italicSystemFontOfSize:13];
    //    _list3.textColor = kCustomColor(150, 150, 150, 1);
    _list3.textColor = [UIColor whiteColor];
    [_backgroundView addSubview:_list3];
    
    _payButten = [UIButton buttonWithType:(UIButtonTypeRoundedRect)];
    _payButten.frame = CGRectMake(_backgroundView.size.width, _backgroundView.size.height - 17 - 37, 65, 37);
    _payButten.layer.cornerRadius = 5;
    _payButten.layer.masksToBounds = YES;
    _payButten.alpha = 0;
    _payButten.backgroundColor = kCustomColor(245, 165, 35, 1);
    [_payButten setTitle:@"购买" forState:(UIControlStateNormal)];
    _payButten.titleLabel.font = [UIFont boldSystemFontOfSize:17];
    [_payButten setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
    [_payButten addTarget:self action:@selector(tapToVIP:) forControlEvents:(UIControlEventTouchUpInside)];
    [_backgroundView addSubview:_payButten];
}


- (void)tapToVIP:(UIButton *)tapSet
{
    
    NSLog(@"kanxiazou le nage fangfa");
    //    PayVC *payVC = [[PayVC alloc] init];
    //    payVC.hidesBottomBarWhenPushed = YES;
    //    [self.navigationController pushViewController:payVC animated:YES];
    //    payVC.hidesBottomBarWhenPushed = NO;
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
